<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="自然语言是人类智慧的结晶，自然语言处理是人工智能中最为困难的问题之一，而对自然语言处理的研究也是充满魅力和挑战的。">
<meta name="keywords" content="AI进阶,机器学习,NLP">
<meta property="og:type" content="article">
<meta property="og:title" content="机器学习-NLP">
<meta property="og:url" content="https://rencheng.cc/2019/04/15/ml/NLP/index.html">
<meta property="og:site_name" content="PHOENIX&#39;s Blog">
<meta property="og:description" content="自然语言是人类智慧的结晶，自然语言处理是人工智能中最为困难的问题之一，而对自然语言处理的研究也是充满魅力和挑战的。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-04-15T08:34:11.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="机器学习-NLP">
<meta name="twitter:description" content="自然语言是人类智慧的结晶，自然语言处理是人工智能中最为困难的问题之一，而对自然语言处理的研究也是充满魅力和挑战的。">



  <link rel="alternate" href="/atom.xml" title="PHOENIX's Blog" type="application/atom+xml">



  
  
  <link rel="canonical" href="https://rencheng.cc/2019/04/15/ml/NLP/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>机器学习-NLP | PHOENIX's Blog</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">PHOENIX's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">Enjoy the journey of life</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://rencheng.cc/2019/04/15/ml/NLP/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="任成">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.JPG">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="PHOENIX's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">机器学习-NLP

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-04-15 16:34:11" itemprop="dateCreated datePublished" datetime="2019-04-15T16:34:11+08:00">2019-04-15</time>
            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/教程/" itemprop="url" rel="index"><span itemprop="name">教程</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          
            <div class="post-symbolscount">
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                <span title="本文字数">6.4k</span>
              

              

              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>自然语言是人类智慧的结晶，自然语言处理是人工智能中最为困难的问题之一，而对自然语言处理的研究也是充满魅力和挑战的。<br><a id="more"></a></p>
<h2 id="NLP"><a href="#NLP" class="headerlink" title="NLP"></a>NLP</h2><p>文本-&gt;语义<br>分类器<br>文本-&gt;特征值<br>今天 中午 我要 吃 饺子<br>NLTK - 自然语言工具包</p>
<h2 id="分词"><a href="#分词" class="headerlink" title="分词"></a>分词</h2><p>使用指南<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line">tk.sent_tokenize(段落) -&gt; 按句拆分</span><br><span class="line">首字母大写、句尾标点(.!?...)</span><br><span class="line">tk.word_tokenize(句子) -&gt; 按单词拆分</span><br><span class="line">n个连续&lt;空格&gt;、换行、标点</span><br><span class="line">分词器 = tk.WordPunctTokenizer()</span><br><span class="line">分词器.tokenize(句子)-&gt;按单词拆分</span><br></pre></td></tr></table></figure></p>
<p>示例<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line">doc = <span class="string">"Are you curious about tokenization? "</span> \</span><br><span class="line">      <span class="string">"Let's see how it works! "</span> \</span><br><span class="line">      <span class="string">"We need to analyze a couple of sentences "</span> \</span><br><span class="line">      <span class="string">"with punctuations to see it in action."</span></span><br><span class="line">print(doc)</span><br><span class="line">tokens = tk.sent_tokenize(doc)</span><br><span class="line"><span class="keyword">for</span> i, token <span class="keyword">in</span> enumerate(tokens):</span><br><span class="line">	print(<span class="string">'%2d'</span> % (i + <span class="number">1</span>), token)</span><br><span class="line">print(<span class="string">'-'</span> * <span class="number">15</span>)</span><br><span class="line">tokens = tk.word_tokenize(doc)</span><br><span class="line"><span class="keyword">for</span> i, token <span class="keyword">in</span> enumerate(tokens):</span><br><span class="line">	print(<span class="string">'%2d'</span> % (i + <span class="number">1</span>), token)</span><br><span class="line">print(<span class="string">'-'</span> * <span class="number">15</span>)</span><br><span class="line">tokenizer = tk.WordPunctTokenizer()</span><br><span class="line">tokens = tokenizer.tokenize(doc)</span><br><span class="line"><span class="keyword">for</span> i, token <span class="keyword">in</span> enumerate(tokens):</span><br><span class="line">	print(<span class="string">'%2d'</span> % (i + <span class="number">1</span>), token)</span><br></pre></td></tr></table></figure></p>
<h2 id="词干提取"><a href="#词干提取" class="headerlink" title="词干提取"></a>词干提取</h2><p>波特：偏宽松，保留更多的字母<br>兰卡斯特：偏严格，只保留较少的字母<br>思诺博：偏中庸，严格程度居于二者这间<br>词干!=词根!=原型<br>语义识别单位<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.stem.porter <span class="keyword">as</span> pt</span><br><span class="line"><span class="keyword">import</span> nltk.stem.lancaster <span class="keyword">as</span> lc</span><br><span class="line"><span class="keyword">import</span> nltk.stem.snowball <span class="keyword">as</span> sb</span><br><span class="line">words = [<span class="string">'table'</span>, <span class="string">'probably'</span>, <span class="string">'wolves'</span>,</span><br><span class="line">         <span class="string">'playing'</span>, <span class="string">'is'</span>, <span class="string">'dog'</span>, <span class="string">'the'</span>,</span><br><span class="line">         <span class="string">'beaches'</span>, <span class="string">'grounded'</span>, <span class="string">'dreamt'</span>,</span><br><span class="line">         <span class="string">'envision'</span>]</span><br><span class="line">pt_stemmer = pt.PorterStemmer()</span><br><span class="line">lc_stemmer = lc.LancasterStemmer()</span><br><span class="line">sb_stemmer = sb.SnowballStemmer(<span class="string">'english'</span>)</span><br><span class="line"><span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">	pt_stem = pt_stemmer.stem(word)</span><br><span class="line">	lc_stem = lc_stemmer.stem(word)</span><br><span class="line">	sb_stem = sb_stemmer.stem(word)</span><br><span class="line">	print(<span class="string">"%8s %8s %8s %8s"</span> % (word, pt_stem,</span><br><span class="line">		lc_stem, sb_stem))</span><br></pre></td></tr></table></figure></p>
<h2 id="词型还原"><a href="#词型还原" class="headerlink" title="词型还原"></a>词型还原</h2><p>名词：变成单数<br>动词：动词原型<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.stem <span class="keyword">as</span> ns</span><br><span class="line">words = [<span class="string">'table'</span>, <span class="string">'probably'</span>, <span class="string">'wolves'</span>,</span><br><span class="line">         <span class="string">'playing'</span>, <span class="string">'is'</span>, <span class="string">'dog'</span>, <span class="string">'the'</span>,</span><br><span class="line">         <span class="string">'beaches'</span>, <span class="string">'grounded'</span>, <span class="string">'dreamt'</span>,</span><br><span class="line">         <span class="string">'envision'</span>]</span><br><span class="line">lemmatizer = ns.WordNetLemmatizer()</span><br><span class="line"><span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">	n_lema = lemmatizer.lemmatize(word, pos=<span class="string">'n'</span>)</span><br><span class="line">	v_lema = lemmatizer.lemmatize(word, pos=<span class="string">'v'</span>)</span><br><span class="line">	print(<span class="string">"%8s %8s %8s"</span> % (word, n_lema, v_lema))</span><br></pre></td></tr></table></figure></p>
<h2 id="词袋模型"><a href="#词袋模型" class="headerlink" title="词袋模型"></a>词袋模型</h2><p>词表：包含段落中不同单词的个数。<br>[1]The brown dog is running.<br>[2]The black dog is in the black room.<br>[3]Running in the room is forbidden.<br>the brown dog is running black in room forbidden<br>           black brown dog forbidden in is room running the<br>[1]         0         1         1           0         0  1    0           1         1<br>[2]         2         0         1           0         1  1    1           0         2<br>[3]         0         0         0           1         1  1    1           1         1<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line"><span class="keyword">import</span> sklearn.feature_extraction.text <span class="keyword">as</span> ft</span><br><span class="line">doc = <span class="string">'The brown dog is running. '</span> \</span><br><span class="line">      <span class="string">'The black dog is in the black room. '</span> \</span><br><span class="line">      <span class="string">'Running in the room is forbidden.'</span></span><br><span class="line">print(doc)</span><br><span class="line">setences = tk.sent_tokenize(doc)</span><br><span class="line">print(setences)</span><br><span class="line"><span class="comment"># 计数矢量化器</span></span><br><span class="line">cv = ft.CountVectorizer()</span><br><span class="line">bow = cv.fit_transform(setences).toarray()</span><br><span class="line">words = cv.get_feature_names()</span><br><span class="line">print(words)</span><br><span class="line">print(bow)</span><br></pre></td></tr></table></figure></p>
<h2 id="词频"><a href="#词频" class="headerlink" title="词频"></a>词频</h2><p>对词袋矩阵做归一化，用词表中的每个单词在每个样本中出现的频率，表示该单词对具体语句语义的价值。<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line"><span class="keyword">import</span> sklearn.feature_extraction.text <span class="keyword">as</span> ft</span><br><span class="line"><span class="keyword">import</span> sklearn.preprocessing <span class="keyword">as</span> sp</span><br><span class="line">doc = <span class="string">'The brown dog is running. '</span> \</span><br><span class="line">      <span class="string">'The black dog is in the black room. '</span> \</span><br><span class="line">      <span class="string">'Running in the room is forbidden.'</span></span><br><span class="line">print(doc)</span><br><span class="line">setences = tk.sent_tokenize(doc)</span><br><span class="line">print(setences)</span><br><span class="line"><span class="comment"># 计数矢量化器</span></span><br><span class="line">cv = ft.CountVectorizer()</span><br><span class="line">bow = cv.fit_transform(setences).toarray()</span><br><span class="line">words = cv.get_feature_names()</span><br><span class="line">print(words)</span><br><span class="line">print(bow)</span><br><span class="line">tf = sp.normalize(bow, norm=<span class="string">'l1'</span>);</span><br><span class="line">print(tf)</span><br></pre></td></tr></table></figure></p>
<script type="math/tex; mode=display">逆文档频率 = \frac{样本总数}{包含某个特定单词的样本数}</script><p>词频逆文档频率：TF-IDF，自然语言的数学模型<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line"><span class="keyword">import</span> sklearn.feature_extraction.text <span class="keyword">as</span> ft</span><br><span class="line">doc = <span class="string">'The brown dog is running. '</span> \</span><br><span class="line">      <span class="string">'The black dog is in the black room. '</span> \</span><br><span class="line">      <span class="string">'Running in the room is forbidden.'</span></span><br><span class="line">print(doc)</span><br><span class="line">setences = tk.sent_tokenize(doc)</span><br><span class="line">print(setences)</span><br><span class="line"><span class="comment"># 计数矢量化器</span></span><br><span class="line">cv = ft.CountVectorizer()</span><br><span class="line">bow = cv.fit_transform(setences).toarray()</span><br><span class="line">words = cv.get_feature_names()</span><br><span class="line">print(words)</span><br><span class="line">print(bow)</span><br><span class="line"><span class="comment"># TF-IDF转换器</span></span><br><span class="line">tt = ft.TfidfTransformer()</span><br><span class="line">tfidf = tt.fit_transform(bow).toarray()</span><br><span class="line">print(tfidf)</span><br></pre></td></tr></table></figure></p>
<h2 id="文本分类"><a href="#文本分类" class="headerlink" title="文本分类"></a>文本分类</h2><p>1 2 3 4 5 6<br>2 3 0 0 4 1<br>0 8 0 0 0 2<br>…<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sklearn.datasets <span class="keyword">as</span> sd</span><br><span class="line"><span class="keyword">import</span> sklearn.feature_extraction.text <span class="keyword">as</span> ft</span><br><span class="line"><span class="keyword">import</span> sklearn.naive_bayes <span class="keyword">as</span> nb</span><br><span class="line">train = sd.load_files(<span class="string">'../data/20news'</span>,</span><br><span class="line">	encoding=<span class="string">'latin1'</span>, shuffle=<span class="literal">True</span>,</span><br><span class="line">	random_state=<span class="number">7</span>)</span><br><span class="line">train_data = train.data</span><br><span class="line">train_y = train.target</span><br><span class="line">categories = train.target_names</span><br><span class="line">cv = ft.CountVectorizer()</span><br><span class="line">train_bow = cv.fit_transform(train_data)</span><br><span class="line">tt = ft.TfidfTransformer()</span><br><span class="line"><span class="comment"># TF-IDF</span></span><br><span class="line">train_x = tt.fit_transform(train_bow);</span><br><span class="line"><span class="comment"># 基于多项分布的朴素贝叶斯分类器</span></span><br><span class="line">model = nb.MultinomialNB()</span><br><span class="line">model.fit(train_x, train_y)</span><br><span class="line">test_data = [</span><br><span class="line">	<span class="string">'The curveballs of right handed pitchers tend to curve to the left'</span>,</span><br><span class="line">	<span class="string">'Caesar cipher is an ancient form of encryption'</span>,</span><br><span class="line">	<span class="string">'This two-wheeler is realy good on slippery roads'</span>]</span><br><span class="line">test_bow = cv.transform(test_data)</span><br><span class="line">test_x = tt.transform(test_bow)</span><br><span class="line">pred_test_y = model.predict(test_x)</span><br><span class="line"><span class="keyword">for</span> sentence, index <span class="keyword">in</span> zip(</span><br><span class="line">	test_data, pred_test_y):</span><br><span class="line">	print(sentence, <span class="string">'-&gt;'</span>, categories[index])</span><br></pre></td></tr></table></figure></p>
<h2 id="情感分析"><a href="#情感分析" class="headerlink" title="情感分析"></a>情感分析</h2><p>一个样本一个tuple: (dict: {特征名: 特征值}, 输出)<br>整个样本集就是一个tuple的list<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> nltk.corpus <span class="keyword">as</span> nc</span><br><span class="line"><span class="keyword">import</span> nltk.classify <span class="keyword">as</span> cf</span><br><span class="line"><span class="keyword">import</span> nltk.classify.util <span class="keyword">as</span> cu</span><br><span class="line">pdata = []</span><br><span class="line">fileids = nc.movie_reviews.fileids(<span class="string">'pos'</span>)</span><br><span class="line"><span class="keyword">for</span> fileid <span class="keyword">in</span> fileids:</span><br><span class="line">	feature = &#123;&#125;</span><br><span class="line">	words = nc.movie_reviews.words(fileid)</span><br><span class="line">	<span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">		feature[word] = <span class="literal">True</span>;</span><br><span class="line">	pdata.append((feature, <span class="string">'POSITIVE'</span>))</span><br><span class="line">ndata = []</span><br><span class="line">fileids = nc.movie_reviews.fileids(<span class="string">'neg'</span>)</span><br><span class="line"><span class="keyword">for</span> fileid <span class="keyword">in</span> fileids:</span><br><span class="line">	feature = &#123;&#125;</span><br><span class="line">	words = nc.movie_reviews.words(fileid)</span><br><span class="line">	<span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">		feature[word] = <span class="literal">True</span>;</span><br><span class="line">	ndata.append((feature, <span class="string">'NEGATIVE'</span>))</span><br><span class="line">pnumb, nnumb = int(<span class="number">0.8</span> * len(pdata)), \</span><br><span class="line">	int(<span class="number">0.8</span> * len(ndata))</span><br><span class="line">train_data = pdata[:pnumb] + ndata[:nnumb]</span><br><span class="line">test_data = pdata[pnumb:] + ndata[nnumb:]</span><br><span class="line">model = cf.NaiveBayesClassifier.train(</span><br><span class="line">	train_data)</span><br><span class="line">ac = cu.accuracy(model, test_data)</span><br><span class="line">reviews = [</span><br><span class="line">	<span class="string">'It is an amazing movie.'</span>,</span><br><span class="line">	<span class="string">'This is a dull movie. I would never recommend it to anyone.'</span>,</span><br><span class="line">	<span class="string">'The cinematography is pretty great in this movie.'</span>,</span><br><span class="line">	<span class="string">'The direction was terrible and the story was all over the place.'</span>]</span><br><span class="line">sents, probs = [], []</span><br><span class="line"><span class="keyword">for</span> review <span class="keyword">in</span> reviews:</span><br><span class="line">	feature = &#123;&#125;</span><br><span class="line">	words = review.split(<span class="string">' '</span>)</span><br><span class="line">	<span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">		feature[word] = <span class="literal">True</span></span><br><span class="line">	pcls = model.prob_classify(feature)</span><br><span class="line">	sent = pcls.max()</span><br><span class="line">	prob = pcls.prob(sent)</span><br><span class="line">	sents.append(sent)</span><br><span class="line">	probs.append(prob)</span><br><span class="line"><span class="keyword">for</span> review, sent, prob <span class="keyword">in</span> zip(</span><br><span class="line">	reviews, sents, probs):</span><br><span class="line">	print(review, <span class="string">'-&gt;'</span>, sent, prob)</span><br></pre></td></tr></table></figure></p>
<h2 id="主题抽取"><a href="#主题抽取" class="headerlink" title="主题抽取"></a>主题抽取</h2><p>基于LDA，隐狄利克雷分布<br><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> warnings</span><br><span class="line">warnings.filterwarnings(</span><br><span class="line">	<span class="string">'ignore'</span>, category=UserWarning)</span><br><span class="line"><span class="keyword">import</span> nltk.tokenize <span class="keyword">as</span> tk</span><br><span class="line"><span class="keyword">import</span> nltk.corpus <span class="keyword">as</span> nc</span><br><span class="line"><span class="keyword">import</span> nltk.stem.snowball <span class="keyword">as</span> sb</span><br><span class="line"><span class="keyword">import</span> gensim.models.ldamodel <span class="keyword">as</span> gm</span><br><span class="line"><span class="keyword">import</span> gensim.corpora <span class="keyword">as</span> gc</span><br><span class="line">doc = []</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'../data/topic.txt'</span>, <span class="string">'r'</span>) <span class="keyword">as</span> f:</span><br><span class="line">	<span class="keyword">for</span> line <span class="keyword">in</span> f.readlines():</span><br><span class="line">		doc.append(line[:<span class="number">-1</span>])</span><br><span class="line">tokenizer = tk.RegexpTokenizer(<span class="string">r'\w+'</span>)</span><br><span class="line">stopwords = nc.stopwords.words(<span class="string">'english'</span>)</span><br><span class="line">stemmer = sb.SnowballStemmer(<span class="string">'english'</span>)</span><br></pre></td></tr></table></figure></p>
<h2 id="结巴分词"><a href="#结巴分词" class="headerlink" title="结巴分词"></a>结巴分词</h2><p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2Z4c2p5L2ppZWJh" title="https://github.com/fxsjy/jieba">GitHub<i class="fa fa-external-link"></i></span></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/AI进阶/" rel="tag"># AI进阶</a>
          
            <a href="/tags/机器学习/" rel="tag"># 机器学习</a>
          
            <a href="/tags/NLP/" rel="tag"># NLP</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/04/11/ml/推荐系统/" rel="next" title="机器学习-推荐系统">
                <i class="fa fa-chevron-left"></i> 机器学习-推荐系统
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/04/20/ml/语音识别/" rel="prev" title="机器学习-语音识别">
                机器学习-语音识别 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.JPG" alt="任成">
            
              <p class="site-author-name" itemprop="name">任成</p>
              <div class="site-description motion-element" itemprop="description"></div>
          </div>

          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL0NvZGVyQ3VydmU=" title="GitHub &rarr; https://github.com/CoderCurve"><i class="fa fa-fw fa-github"></i>GitHub</span>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="bWFpbHRvOnJlbmNoZW5nMTFAaWNsb3VkLmNvbQ==" title="E-Mail &rarr; mailto:rencheng11@icloud.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#NLP"><span class="nav-number">1.</span> <span class="nav-text">NLP</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分词"><span class="nav-number">2.</span> <span class="nav-text">分词</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#词干提取"><span class="nav-number">3.</span> <span class="nav-text">词干提取</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#词型还原"><span class="nav-number">4.</span> <span class="nav-text">词型还原</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#词袋模型"><span class="nav-number">5.</span> <span class="nav-text">词袋模型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#词频"><span class="nav-number">6.</span> <span class="nav-text">词频</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文本分类"><span class="nav-number">7.</span> <span class="nav-text">文本分类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#情感分析"><span class="nav-number">8.</span> <span class="nav-text">情感分析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#主题抽取"><span class="nav-number">9.</span> <span class="nav-text">主题抽取</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结巴分词"><span class="nav-number">10.</span> <span class="nav-text">结巴分词</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">  <span class="exturl" data-url="aHR0cDovL3d3dy5iZWlhbi5taWl0Lmdvdi5jbg==">京ICP备18001214号 </span>&copy; 2014 – <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">任成</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
    <span title="站点总字数">277k</span>
  

  
</div>









        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/affix.js?v=7.1.2"></script>

  <script src="/js/schemes/pisces.js?v=7.1.2"></script>



  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  
  <script src="/js/exturl.js?v=7.1.2"></script>


  

  


  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
  

  
  

  


  

  
<script>
if ($('body').find('pre.mermaid').length) {
  $.ajax({
    type: 'GET',
    url: '//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js',
    dataType: 'script',
    cache: true,
    success: function() {
      mermaid.initialize({
        theme: 'forest',
        logLevel: 3,
        flowchart: { curve: 'linear' },
        gantt: { axisFormat: '%m/%d/%Y' },
        sequence: { actorMargin: 50 }
      });
    }
  });
}
</script>


  

  

  

  

  

  

  

  

  

</body>
</html>
